import torch
from transformers import AutoModel, AutoProcessor
from transformers.image_utils import load_image

# 设置设备
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# load the model and processor
ckpt = "D:/model/siglip2"
model = AutoModel.from_pretrained(ckpt).to(device).eval()
processor = AutoProcessor.from_pretrained(ckpt)

# load the image
image = load_image("https://huggingface.co/datasets/merve/coco/resolve/main/val2017/000000000285.jpg")
inputs = processor(images=[image], return_tensors="pt").to(device)

# run infernece
with torch.no_grad():
    image_embeddings = model.get_image_features(**inputs)    

print(image_embeddings.shape)